package com.atguigu.aiproject.controller.user;

import com.atguigu.aiproject.entity.Result;
import com.atguigu.aiproject.service.FollowService;
import com.atguigu.aiproject.vo.FollowCoverVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/follow")
@CrossOrigin
public class FollowController {
    @Autowired
    private FollowService followService;
    /**
     * 关注或取关
     */
    @PutMapping("/{id}/{isFollow}")
    public Result<?> follow(@PathVariable("id") Integer followUserId, @PathVariable("isFollow") Boolean isFollow) {
        followService.follow(followUserId, isFollow);
        return Result.success();
    }

    /**
     * 判断是否关注
     */
    @GetMapping("/or/not/{id}")
    public Result<Boolean> isFollow(@PathVariable("id") Integer followUserId) {
        return Result.success(followService.isFollow(followUserId));
    }
    /**
     * 查找我的关注列表或粉丝列表
     * type为 follow为关注列表，为 fans为粉丝列表
     */
    @GetMapping("/list/{type}")
    public Result<List<FollowCoverVO>> findFollow(@PathVariable("type") String type) {
        return Result.success(followService.findFollowList(type));
    }
}
